<?php
/*
 * Created on 2012-5-8
 * @iChying
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 include_once('compress.php');
 include_once('decompress.php');
 include_once($_SERVER["DOCUMENT_ROOT"].'/URL/Charset/PHPConvert.php');

 class ChineseEncode {
 	private $compressHandler;
 	private $decompressHandler;
 	private $charsetConvertHandler;

 	public function __construct() {
 		$this->compressHandler = new UnicodeCompress();
 		$this->decompressHandler = new UnicodeDecompress();
 		$this->charsetConvertHandler = new PHPCharsetConvert();
 	}

 	public function paramEncode($chineseParam, $encoding = 'GBK') {
 		$unicodeValue = 0;

 		switch($encoding) {
 			case 'GB2312' : case 'GBK':
 			case 'gb2312' : case 'gbk':
 				$unicodeValue = $this->charsetConvertHandler->GBK2Unicode($chineseParam);
 				break;

 			case 'UTF-8' : case 'UTF-8':
 				$unicodeValue = $this->charsetConvertHandler->UTF82Unicode($chineseParam);
				break;

			case 'BIG5' : case 'Big5' : case 'big5':
				$unicodeValue = $this->charsetConvertHandler->BIG52Unicode($chineseParam);
				break;

			default: break;
 		}

 		$unicodeEncoded = $this->compressHandler->compressUnicode($unicodeValue);
 		return $unicodeEncoded;
 	}

 	public function paramDecode($unicodeEncoded, $encoding = 'GBK') {
 		$unicodeValue = hexdec($this->decompressHandler->decompressUnicode($unicodeEncoded));

 		switch($encoding) {
 			case 'GB2312' : case 'GBK':
 			case 'gb2312' : case 'gbk':
 				$unicodeValue = $this->charsetConvertHandler->Unicode2GBKentity($unicodeValue);
 				break;

 			case 'UTF-8' : case 'UTF-8':
 				$unicodeValue = $this->charsetConvertHandler->Unicode2UTF8entity($unicodeValue);
				break;

			case 'BIG5' : case 'Big5' : case 'big5':
				$unicodeValue = $this->charsetConvertHandler->Unicode2BIG5entity($unicodeValue);
				break;

			default: break;
 		}

 		$chineseParam = $unicodeValue;
 		return $chineseParam;
 	}
 }

?>